﻿using System.Text.RegularExpressions;

namespace JSH.ITDiplom.OOPC01.PersonalIdentityNumber.BusinessLayer.se
{
    /// <summary>
    /// Swedish format validation.
    /// Uses Regular expression.
    /// </summary>
    class FormatValidation : IPersonalIdentityNumberValidation
    {
        private static readonly Regex regExPattern = 
            new Regex("^(((0|1|2)[0-9])|(3[0-1]))((0[1-9])|(1[0-2]))[0-9]{2}(-|\\+){1}[0-9]{4}$");
        private readonly string personalIdentityNumber;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="personalIdentityNumber">Personal identity number</param>
        public FormatValidation(string personalIdentityNumber)
        {
            this.personalIdentityNumber = personalIdentityNumber;
        }

        /// <summary>
        /// Validate.
        /// </summary>
        /// <returns>Returns true if personal identity number is valid</returns>
        public bool Validate()
        {
            return regExPattern.IsMatch(personalIdentityNumber);
        }
    }
}